package com.itxx.homework;

import java.util.ArrayList;
import java.util.HashSet;

/*
* 3.1 ArrayList有以下元素: "a","f","b","c","a","d"，请用任意方式完成集合元素去重。去除集合中重复的元素。*/
public class Test5 {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        list.add("a");
        list.add("f");
        list.add("b");
        list.add("c");
        list.add("a");
        list.add("d");
        //将所有元素放到HashSet中
        HashSet<String> hashSet = new HashSet<>();
        hashSet.addAll(list);
        //将list中的元素清空,将HashSet中的元素放到list中去
        list.clear();
        list.addAll(hashSet);
        System.out.println(list);
        list.stream().distinct().forEach(s-> System.out.println(s));


    }
}
